import requests
from lxml import etree

i = 1
while True:
    print(f'开始爬取第 {i} 页')
    url = f'https://ypk.39.net/saftydrugs/t0_p{i}/'
    res = requests.get(url)
    tree = etree.HTML(res.text)
    lis = tree.xpath('//ul[@class="related-art1"]/li')
    a = tree.xpath('//a/text()')
    for li in lis:
        detail_url = f'https://ypk.39.net{li.xpath('.//a/@href')[0]}'
        print(detail_url)
    if '下页' not in a:
        break
    else:
        i = i + 1